# comun: small self hosted interpreter
#
# This is a comun interpreter that's supposed to be small, it only has the
# necessary features to interpret given bytecode. This is useful for smaller
# devices, bootstrapping or Unix style piping. This interpreter doesn't perform
# optimizations or give extensive warnings.
#
# usage: takes bytecode on input and runs it (on error writes out short message) 

writeError: "ERR A" -> -> -> -> + -> 10 -> .

CMN_iIn: <? ? <- ; -1 . .
CMN_iOut: -> .
CMN_iGetArgs: 0 .
CMN_iCallExt: ^ 21 writeError .

CMN_bBYTECODE_SIZE: ~32 16384 ~0 .
~16 ~CMN_bBytecode:16384 ~0

CMN_iMEM_SIZE: ~32 16384 ~0 .
~32 ~CMN_iMem:16384 ~0

~"cmn_interpreter.cmn"

CMN_eLoadBC !! ?
  20 writeError
  !.
.

CMN_bCheckSanity !! ?
  "ERR BC" -> -> -> -> -> -> 10 ->
  !.
.

32 CMN_iInit
  
@@
  $CMN_iState CMN_iSTATE_RUNNING != ?
    !@
  .

  CMN_iStep
.

$CMN_iState CMN_iSTATE_DONE != ?
  $CMN_iState writeError
.
